package com.vito.dcs.sys.deviceSet.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import com.vito.base.model.Result;
import com.vito.base.tools.I18nResMsg;
import com.vito.base.util.Validata;
import com.vito.dcs.sys.deviceSet.model.DeviceSetModel;
import com.vito.dcs.sys.deviceSet.service.DeviceSetService;

/**
 * 数据上报接收频率
 * @author lyhao
 *
 */
@Controller
@RequestMapping("/dcs/sys/deviceSet")
public class DeviceSetAction extends BaseAction{

	private static final Logger log = LoggerFactory.getLogger(DeviceSetAction.class);
	
	@Reference
	private DeviceSetService deviceSetService;
	
	/**
	 * 保存
	 * @param deviceSetModel
	 * @return
	 */
	@RequestMapping("/saveDeviceSet")
	@ResponseBody
	public Result saveDeviceSet(DeviceSetModel deviceSetModel){
		Result res = new Result();
		UserModel obj = SessionMap.getObj();
		
		if(obj == null || Validata.isNullOrEmpty(obj.getUserId())){
			res.setCode(Result.CODE_LOGIN_REQUIRE);
			res.setMsg(I18nResMsg.MSG_LOGIN_NEED());
			return res;
		}
		try {
			deviceSetModel.setUpdateUser(obj.getUserId());
			deviceSetService.saveDeviceSet(deviceSetModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(I18nResMsg.SAVESUC());
		} catch (Exception e) {
			res.setCode(Result.CODE_ERROR);
			res.setMsg(I18nResMsg.SAVEERR());
			log.error(I18nResMsg.SAVEERR(), e);
		}
		return res;
	}
	/**
	 * 查询
	 * @param deviceSetModel
	 * @return
	 */
	@RequestMapping("/queryDeviceSetBySectionId")
	@ResponseBody
	public Result queryDeviceSetBySectionId(DeviceSetModel deviceSetModel){
		Result res = new Result();
		try {
			res.setCode(Result.CODE_OK);
			res.setData(deviceSetService.queryDeviceSetBySectionId(deviceSetModel));
		} catch (Exception e) {
			res.setCode(Result.CODE_ERROR);
			res.setMsg("查询失败");
			log.error("查询失败", e);
		}
		return res;
	}
	
}
